﻿
function main() {
    showLog("抖音(推荐评论点赞)");
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var terminationNum = viewJson.terminationNum;
    var shutdwon=0;
    AccessibilityEngine.sleepEngine(5000);//等待
    // chuSiHua(widget.pages.shouye.bugengxin);
    // AccessibilityEngine.sleepEngine(2000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    for (var i =0 ; i <search; i ++ ){  // 循环滑动
		if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
			AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
		}
		if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
			AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
		}
        var nowArray = new Array();
        var hasRunOperate =true;

        AccessibilityEngine.sleepEngine(3000);//等待
        if( jixing == 1 ){// 判断机型
            var pressjixing = "press," + parseX(660) + "," + parseY(757);
            ScreenEngine.currency(pressjixing);
        } else if( jixing == 2 ){
            ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //点击三个点 评论
        }
        for (var ii=0 ; ii<=20 ;ii++){// 判断是否进入评论区
            if ( AccessibilityEngine.checkUpText("留下你的精彩评论吧") == ISFALSE){
                if( jixing == 1 ){
                    var pressjixing = "press," + parseX(660) + "," + parseY(763);
                    ScreenEngine.currency(pressjixing);
                } else if( jixing == 2 ){
                    ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //点击三个点 评论
                }
            }else {
                break;
            }
            AccessibilityEngine.sleepEngine(3000);
            if (ii==20){
                setTaskState("5", "脚本执行完毕");
                throw SyntaxError();
            }
        }
        if (AccessibilityEngine.checkUpIdText(widget.pages.fasongxiaoxi.plzf, "评论并转发")==ISTRUE){
            showLog("误点评论返回");
            i--;
            AccessibilityEngine.mockBack();
            AccessibilityEngine.sleepEngine(2000);//等待
            AccessibilityEngine.mockBack();
            AccessibilityEngine.sleepEngine(2000);//等待
            ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
            continue;
        }
        if (  AccessibilityEngine.checkUpText("暂无评论") == ISTRUE ){
            if ( AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang ) == ISTRUE) {
                showLog("进来就评论");
                AccessibilityEngine.mockBack();
                ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
                i--;
                continue;
            }

        }
        if (AccessibilityEngine.checkUpId( widget.pages.shouye.fasong )==ISTRUE){
            showLog("误点评论返回");
            i--;
            AccessibilityEngine.mockBack();
            AccessibilityEngine.sleepEngine(2000);//等待
            if ( AccessibilityEngine.checkUpId( widget.pages.shouye.pinglunKuang ) == ISTRUE){
                showLog("进来就评论");
                AccessibilityEngine.mockBack();
                AccessibilityEngine.sleepEngine(2000);//等待
                ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
                continue;
            }
        }

        var termination=0;
        aaa:while (termination < terminationNum){
			if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
			}
			if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
			}
            if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/bfs") == ISTRUE) { //点赞小心s
                var zanIdNum = AccessibilityEngine.getIdNum("com.ss.android.ugc.aweme:id/bfs");
                showLog('zanIdNum' + zanIdNum);
                for (var zan = 0; zan < zanIdNum; zan++) {
					if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
						AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
					}
					if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
						AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
					}
                    AccessibilityEngine.sleepEngine(300);//等待
                    AccessibilityEngine.mockOnClickIdIndex("com.ss.android.ugc.aweme:id/bfs", zan); //逐个小心
                    termination++;
                    if (termination >= terminationNum) {
                        AccessibilityEngine.mockBack();
                        break aaa;
                    }
                }
                if (AccessibilityEngine.checkUpText("暂时没有更多了") == ISTRUE ) {
                    showLog("暂时没有更多了点击返回");
                    AccessibilityEngine.mockBack();
                    break  aaa;
                }
                AccessibilityEngine.sleepEngine(1500);//等待
                showLog("滑动滑动滑动");
                ScreenEngine.swipe(parseX(500), parseY(900), parseX(500), parseY(300), 1000);
                AccessibilityEngine.sleepEngine(1500);//等待
                ScreenEngine.swipe(parseX(500), parseY(900), parseX(500), parseY(300), 1000);
            } else {
                AccessibilityEngine.mockBack();
                break;
            }
        }
        AccessibilityEngine.sleepEngine(1000);
        ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
		if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
			AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
		}
		if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
			AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
		}
    }
    showLog("显示执行成功");
    setTaskState("5", "脚本执行完毕");
    throw SyntaxError();
}

var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();
